package com.libinyn.base.pms.serivce.impl.sys;


import com.libinyn.base.pms.entity.sys.SysRoleMenuEntity;
import com.libinyn.base.pms.mapper.sys.SysRoleMenuMapper;
import com.libinyn.base.pms.serivce.impl.BaseServiceImpl;
import com.libinyn.base.pms.serivce.sys.SysRoleMenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 角色与菜单对应关系
 * @fileName: SysRoleMenuServiceImpl.java
 * @author: bin.li01
 * @date: 2017/12/15 13:47
 * @version: v1.0.0
 */
@Service
public class SysRoleMenuServiceImpl extends BaseServiceImpl<SysRoleMenuEntity> implements SysRoleMenuService {

	@Resource
	private SysRoleMenuMapper sysRoleMenuDao;

	@Override
	public void saveOrUpdate(Long roleId, List<Long> menuIdList) {
		//先删除角色与菜单关系
		sysRoleMenuDao.deleteByPrimaryKey(roleId);

		if(menuIdList.size() == 0){
			return ;
		}

		//保存角色与菜单关系
		Map<String, Object> map = new HashMap<>();
		map.put("roleId", roleId);
		map.put("menuIdList", menuIdList);
		sysRoleMenuDao.insertSelective(new SysRoleMenuEntity());
	}

	@Override
	public List<Long> queryMenuIdList(Long roleId) {
		return sysRoleMenuDao.queryMenuIdList(roleId);
	}

}
